/*                                      _
 *     ___ _ __ ___ _ __ ___   ___   __| |
 *    / __| '__/ __| '_ ` _ \ / _ \ / _` |
 *    \__ \ |  \__ \ | | | | | (_) | (_| |
 *    |___/_|  |___/_| |_| |_|\___/ \__,_|                                  
 *
 *     _  _  _ _ |_ .|_ ._|_  |_  _  _ _ _ _
 * |_|| ||_)| (_)| |||_)| |   |_)(_)_\_\(/_\                
 *       |    _ _  _  _|   | _ 
 *           | | |(_)(_||_||(/_
 *                    
 */

#define MODULE_NAME "UnprohibitBosses"
#define GAMECONFIG_FILE "left4downtown.l4d2"

#define SRS_BOSSES_UNPROHIBIT_BOSSES_VALUE 0							// l4d2 checks if script key is non-0 to prohibit bosses

new Handle:cvarProhibitBosses = INVALID_HANDLE;

UnprohibitBosses_OnPluginStart()
{
	new Handle:conf = LoadGameConfigFile(GAMECONFIG_FILE);
	if(conf == INVALID_HANDLE) 
	{
		Debug_Print("Could not load gamedata/%s.txt", GAMECONFIG_FILE);
		//SetFailState("Could not load gamedata/%s.txt", GAMECONFIG_FILE);
	}
	
	Debug_SearchForFunction(conf, "CDirector_GetScriptValueInt");

	cvarProhibitBosses = CreateConVar("l4d2_srs_bosses_unprohibit", "1", "Allow tanks to spawn on maps that normally prohibit it", SRS_CVAR_DEFAULT_FLAGS);
}

public Action:L4D_OnGetScriptValueInt(const String:key[], &retVal)
{
	Debug_PrintSpam("OnGetScriptValueInt(key=\"%s\",retVal=%d)", key, retVal); 
	
	if(GetConVarInt(cvarProhibitBosses) && StrEqual(key, "ProhibitBosses")) 
	{
		Debug_PrintSpam("Overriding OnGetScriptValueInt(ProhibitBosses)...");
		retVal = SRS_BOSSES_UNPROHIBIT_BOSSES_VALUE;
		return Plugin_Handled; // return the new overridden value
	}
	
	return Plugin_Continue;
}

#undef MODULE_NAME
#undef GAMECONFIG_FILE
